package fpt.edu.vn.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fpt.edu.vn.dao.AddnewDao;
import fpt.edu.vn.dao.LocationDao;
import fpt.edu.vn.model.Locations;
import fpt.edu.vn.model.Locationtypes;
import fpt.edu.vn.model.Provinces;

/* 
 * AdminLocationLoadAction.java 
 *  
 * 0.1
 * 
 * 10/15/2012 
 *  
 * Copyright notice 
 *  
 * Modification Logs: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  -------------------------------------------------------- 
 *  15-Oct-2012  ThuongND    Create new 
 */
public class AdminLocationLoadAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String email;

	private String Username;

	private List<Provinces> lstProvince;
	private List<Locationtypes> lstLocationtypes;
	private List<Locations> lstLocation;
	private int locationTypeId;
	private AddnewDao addnewdao = new AddnewDao();
	private LocationDao locationdao = new LocationDao();
	// For SessionAware
	Map<String, Object> session;

	public String execute() {
		session = ActionContext.getContext().getSession();
		if (session.containsKey("userRoleIdss")) {
			email = (String) session.get("emailss");
			int isAdmin = (Integer) session.get("userRoleIdss");
			if (isAdmin == 1) {
				// get district
				this.lstProvince = addnewdao.getProvince();
				this.lstLocationtypes = addnewdao.getLocationtypes();
				if(locationTypeId==0)
					locationTypeId=1;
				this.lstLocation = locationdao.lstlocationload(0, locationTypeId);
				return SUCCESS;
			} 
		}
		return ERROR;

	}

	public Date getSysdate() {
		Date date = new Date();
		return date;
	}

	public String getStrDate() {
		String curdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
				.format(Calendar.getInstance().getTime());
		return curdate;
	}
	
	public int getLocationTypeId() {
		return locationTypeId;
	}

	public void setLocationTypeId(int locationTypeId) {
		this.locationTypeId = locationTypeId;
	}

	public List<Locations> getLstLocation() {
		return lstLocation;
	}

	public void setLstLocation(List<Locations> lstLocation) {
		this.lstLocation = lstLocation;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
		return Username;
	}

	public void setUsername(String username) {
		Username = username;
	}

	public List<Locationtypes> getLstLocationtypes() {
		return lstLocationtypes;
	}

	public void setLstLocationtypes(List<Locationtypes> lstLocationtypes) {
		this.lstLocationtypes = lstLocationtypes;
	}

	public List<Provinces> getLstProvince() {
		return lstProvince;
	}

	public void setLstProvince(List<Provinces> lstProvince) {
		this.lstProvince = lstProvince;
	}
}
